package com.plian.system.task;

import com.plian.system.service.fr.indicators.IComplexIndicatorsValueService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;

@Slf4j
@Component
@RequiredArgsConstructor
public class ComplexIndicatorsTask {

    private final IComplexIndicatorsValueService complexIndicatorsService;

    @Scheduled(cron = "0 0 0 * * ? ")
    public void updateStatus(){
        log.info("直接监管企业 净资产收益率、归母净资产收益率 生成 ------------>" + LocalDateTime.now());
        Calendar cal = Calendar.getInstance();
        Date date=new Date();//现在的日期
        cal.setTime(date);
        int month = cal.get(Calendar.MONTH) + 1;
        int year = cal.get(Calendar.YEAR);
        int startMonth = month - 3 > 0 ? month - 3 : 1;
        for (int i = startMonth; i <= month; i++) {
            complexIndicatorsService.updateByYearAndMonth(year, i);
        }
        log.info("直接监管企业 净资产收益率、归母净资产收益率 结束 ------------> " + LocalDateTime.now());
    }
}
